package com.anzia.reader;

import java.io.BufferedReader;
import java.io.FileReader;

/**
 *@ClassName BufferedReader_Demo
 *@Description
 *@Author Anzia.
 *@Date 2021/4/9 16:20
 *@Version 1.0
 **/
public class BufferedReader_Demo {
    public static void main(String[] args) throws Exception {
        //创建缓冲流
        FileReader fr = new FileReader("static\\write.txt");
        BufferedReader br = new BufferedReader(fr);
        BufferedReader_Demo demo = new BufferedReader_Demo();

        //读取
        //demo.line_read(br);
        demo.line_read(br);

        //关闭
        br.close();
        System.out.println("执行完毕！");
    }

    public void normal_read(BufferedReader br) throws Exception {
        char[] chars = new char[1024];
        int count = 0;
        while ((count = br.read(chars)) != -1) {
            System.out.println(new String(chars, 0, count));
        }
    }

    public void line_read(BufferedReader br) throws Exception {
        String line = null;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
    }
}
